<?php

namespace App\Http\Controllers;

//use Illuminate\Http\Request;
use Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Models\Book;
use App\Models\BooksComments;
use App\Models\Category as cat;
use App\Models\Shudan;
use App\Models\BooksReview;
use App\Models\Bags;
use Session;
use Redirect;

class IndexController extends Controller
{

    public function index()
    {

        //获得所有图书信息的数据->books数据库 前几个
        $books = Book::limit(36)->orderBy('last_update', 'desc')->orderBy('book_id', 'desc')->get();

        $booksreviews = BooksReview::limit(5)->orderBy('id', 'desc')->get();
        foreach($booksreviews as $booksreview)
        {
            //为了得到图书的信息
            $booksreview['books'] = $booksreview->hasOnebooks;
        }
        foreach ($booksreviews as $reviewuser) {
            //得到发布长评论的会员资料
            $reviewuser['users'] = $reviewuser->hasOnUsersReg;
        }

        //转让或出借的图书列表
        $bags = Bags::limit(12)->orderBy('add_time', 'desc')->get();
        foreach($bags as $bag)
        {
            //为了得到交换图书的信息
            $bag['books'] = $bag->hasOnebooks;
        }
        foreach ($bags as $bag) {
            //得到交换图书的会员资料
            $bag['users'] = $bag->hasTcUsersReg;
        }

        //书籍分类
        $fenleis = Cat::get();
        //书单列表
        $shudans = Shudan::limit(15)->orderBy('last_time', 'desc')->get();

        return view('books.layouts.index', array(
            'books' => $books,
            'booksreviews' => $booksreviews,
            'bags' => $bags,
            'fenleis' => $fenleis,
            'shudans' => $shudans
            ));
    }

}
